#include <VirtualWire.h>  // you must download and install the VirtualWire.h to your hardware/libraries folder

const int steeringInput = A0;  // Analog input pin that the steering potentiometer is attached to
const int speedInput = A1;  // Analog input pin that the speed potentiometer is attached to

volatile unsigned long steeringValue = 511;
char steeringValue_char[4];
volatile unsigned long speedValue = 511;
char speedValue_char[4];

unsigned long messageValue = 0;
char messageValue_char[4];

// DEBUG VARS
long debug;
// END DEBUG VARS

void setup()
{
     // Initialise the IO and ISR
    vw_set_ptt_inverted(true); // Required for RF Link module
    vw_setup(2000);                 // Bits per sec
    vw_set_tx_pin(3);                // pin 3 is used as the transmit data out into the TX Link module, change this to suit your needs. 
}

void loop()
{
  const char *msg = "Rosilene cocodilha";       // this is your message to send
  steeringValue = analogRead(steeringInput);
  speedValue = analogRead(speedInput);
  
  messageValue = (((steeringValue<<10)&0xFFC00) + (speedValue&0x3FF));
  
  debug = (steeringValue<<10)&0xFFC00;
  
  Serial.print("Debug Value: ");
  Serial.print(debug);
  Serial.println();
  
  // Convert the steering integer data to Char array directly 
  itoa(messageValue,messageValue_char,10);
  
  Serial.print("Message Value: ");
  Serial.print(messageValue);
  Serial.println();
  
  // DEBUG
  Serial.print("Steering Value: ");
  Serial.print(steeringValue);
  Serial.println();
  Serial.print("Speed Value: ");
  Serial.print(speedValue);
  Serial.println();
  // END DEBUG

  vw_send((uint8_t *)messageValue_char, strlen(messageValue_char));
  vw_wait_tx();   // Wait for message to finish
  Serial.print("Mensagem enviada: ");
  Serial.print(steeringValue_char);
  Serial.println();
  delay(250);
}
